<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout">
<head th:replace="dashboard/header :: header"></head>

<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="operlog-form">
					<div class="select-list">
						<ul>
							<li>
								<label>应用名称： </label><input type="text" name="condition[applicationName|like]"/>
							</li>
							<li>
								<label>工程名称： </label><input type="text" name="condition[feignServerPath|like]"/>
							</li>
							<li>
								<label>数据库： </label><input type="text" name="condition[dbUrl|like]"/>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.add()">
	                <i class="fa fa-plus"></i> 新增
	            </a>
				<a class="btn btn-danger btn-del disabled" onclick="$.operate.removeAll()">
		            <i class="fa fa-remove"></i> 删除
		        </a>
		        <a class="btn btn-danger" onclick="$.operate.clean()">
	                <i class="fa fa-trash"></i> 清空
	            </a>
	            <a class="btn btn-warning" onclick="$.table.exportExcel()">
		            <i class="fa fa-download"></i> 导出
		        </a>
	        </div>
	        
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
	
	<!-- 提示弹窗_start -->
	<!-- 提示弹窗_end -->
	
	<footer th:replace="dashboard/footer :: footer"></footer>

	<script>
		var detailFlag = "";
		var downloadFlag = "";
		var datas = "" ; 
		var prefix = ctx + "monitor/operlog";

		$(function() {
		    var options = {
		        url: ctx+"portal/ucenter/source/datatables" ,
		        cleanUrl: prefix + "/clean",
		        createUrl: ctx + 'portal/ucenter/source/add' ,
		        updateUrl: ctx+"portal/ucenter/source/modify?id={id}" ,
		        detailUrl: ctx+"portal/ucenter/source/detail?id={id}",
		        removeUrl: ctx+"portal/ucenter/source/delete" ,
		        uploadUrl:ctx+"portal/ucenter/source/code?id=" ,
		        exportUrl: prefix + "/export",
		        sortName: "operTime",
		        uniqueId:"id" ,
		        sortOrder: "desc",
		        modalName: "代码生成",
		        escape: true,
		        showPageGo: true,
		        rememberSelected: true,
		        columns: [{field: 'state',checkbox: true },
		        	 
			        {field: 'applicationName', title: '应用名称' , align:'left' , formatter:function(value , row , index){
			                var actions = [] ;
			                actions.push('<a class="btn" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.id + '\')">'+value+'</a> ');
			                return actions.join('') ;
			        }},
			        {field: 'feignServerPath', title: '工程名称'},
			        {field: 'dbUrl', title: '数据库'},
			        {field: 'feignServerPath', title: '持续集成' , align:'center' , formatter:function(value , row , index){
			                var actions = [] ;
			                actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="fastCI(\'' + row.id + '\')"><i class="fa fa-paper-plane"></i>一键集成</a> ');
			                return actions.join('') ;
			        }},
			        {field: 'feignServerPath', title: '应用类型' , align:'center' , formatter:function(value , row , index){
			                var actions = [] ;
			                if(row.serviceProject){
				                actions.push('<i class="fa fa-bitbucket" aria-hidden="true"></i> 分布式') ; 
			                }else{
				                actions.push('<i class="fa fa-bitbucket" aria-hidden="true"></i> 单体') ; 
			                }
			                return actions.join('') ;
			        }},
			        {field: 'addTime', title: '添加时间'}, 
			        
			        {field: 'id' , title: '操作',  align: 'center',  formatter: function(value, row, index) {
			                var actions = [];
			                // actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.id + '\')"><i class="fa fa-search"></i>详细</a> ');
			                actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');

			                actions.push('<a class="btn btn-success btn-xs" href="'+options.uploadUrl+row.id+'"" ><i class="fa fa-download"></i>代码</a> ');
			                actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="buildGit(\'' + row.id + '\')" ><i class="fa fa-github"></i>仓库</a> ');
			                actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="buildJenkins(\'' + row.id + '\')"><i class="fa fa-paper-plane"></i>集成</a> ');
			                return actions.join('');
			          }
			     }]
		    };
		    $.table.init(options);
		});
	
		function buildGit(_id){
		    var downloadUrl = ctx + "portal/ucenter/source/git?id=" + _id ;
		    $.modal.loading("代码上传中");
			
			$.get(downloadUrl , function(response){
				$.modal.closeLoading();
				if(response.code == 200){
					$.modal.alert("代码上传git成功.") ; 
				}else{
					$.modal.alert(response.message) ; //"代码上传git失败.") ; 
				}
			},'JSON') ;
		}
		
		function buildJenkins(_id){
		    var downloadUrl = ctx + "portal/ucenter/source/jenkins?id=" + _id ;
		    $.modal.loading("数据加载中");
			
			$.get(downloadUrl , function(response){
				$.modal.closeLoading();
				if(response.code == 200){
					$.modal.alert("持续集成Jenkins成功.") ; 
				}else{
					$.modal.alert(response.message) ; 
				}
			},'JSON') ;
		}
		
		function fastCI(_id){
		    var downloadUrl = ctx + "portal/ucenter/source/ci?id=" + _id ;
		    $.modal.loading("持续集成中");
			
			$.get(downloadUrl , function(response){
				$.modal.closeLoading();
				if(response.code == 200){
					$.modal.alert("持续集成完成，完成持续集成工作<br/>"+
							"Git初始化完成:xxxxx  <br/> "+
							"Jenkins任务:xxxxx <br/>"+
							"镜像地址:xxxxx <br/>"+
							"请登陆查看.") ; 
				}else{
					$.modal.alert(response.message) ; 
				}
			},'JSON') ;
		}

	</script>
</body>
</html>